﻿#ifndef JZ_DBCONDITION_H_
#define JZ_DBCONDITION_H_

#include <QString>
#include <QVariant>
#include <QSqlField>
#include <QSharedPointer>

class JZDbCondition 
{
public:
    enum CondType{
        None,
        Operator,
        Field,
        Value,
    };

    JZDbCondition();
    explicit JZDbCondition(QVariant v);
    explicit JZDbCondition(QSqlField field);
    JZDbCondition(const QString& op, JZDbCondition left, JZDbCondition right);
    JZDbCondition(const JZDbCondition &other);
    ~JZDbCondition();

    QString condition() const;

    void copyTo(JZDbCondition *other) const;

    void operator=(const JZDbCondition& other);
    JZDbCondition operator&&(const JZDbCondition& other) const;
    JZDbCondition operator||(const JZDbCondition& other) const;

protected:
    CondType m_type;
    QString m_op;
    QSharedPointer<JZDbCondition> m_left;
    QSharedPointer<JZDbCondition> m_right;
};

JZDbCondition operator>(const QSqlField& field, const QVariant& value);
JZDbCondition operator<(const QSqlField& field, const QVariant& value);
JZDbCondition operator>=(const QSqlField& field, const QVariant& value);
JZDbCondition operator<=(const QSqlField& field, const QVariant& value);
JZDbCondition operator==(const QSqlField& field, const QVariant& value);
JZDbCondition operator!=(const QSqlField& field, const QVariant& value);

#endif // !JZ_DBCONDITION_H_